package leetCode;

public class t34 {
    public static void main(String[] args) {
        int[] nums=new int[]{1};
        Solution.searchRange(nums,1);
    }
    static class Solution {
        public static int[] searchRange(int[] nums, int target) {
            int leftIndex=binarySearch(nums,target,true);
            int rightIndex=binarySearch(nums,target,false)-1;
            if (leftIndex>rightIndex){
                return new int[]{-1,-1};
            }
            return new int[]{leftIndex,rightIndex};
        }
        public static int binarySearch(int[] nums,int target,boolean lower){
            int left=0;
            int right=nums.length-1;
            int ans=nums.length;
            while (left<=right){
                int mid=(right+left)/2;
                if (nums[mid]>target||(lower&&nums[mid]>=target)){
                    ans=mid;
                    right=mid-1;
                }else {
                    left=mid+1;
                }
            }
            return ans;

        }
    }
}
